//
//  MMMainViewController.swift
//  苗苗微博
//
//  Created by playboy_ming on 16/8/22.
//  Copyright © 2016年 playboy_ming. All rights reserved.
//

import UIKit

class MMMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        setupChildViewControllers()
    }
    
}

extension MMMainViewController{
    
    
    private func setupChildViewControllers(){
    
        let array = [["title":"首页","clsName":"MMHomeViewController","imageName":""]]
        
        var arraryM = [UIViewController]()
        for dict in array
        {
            arraryM.append(controller(dict))
        }
        
        viewControllers = arraryM
        
    }
    
    //MARK : - 使用字典创建自控制器
    private func controller(_ dict:[String:String]) -> UIViewController{
    
        guard let clsName = dict["clsName"],
                     let title = dict["title"],
                    let _ = dict["imageName"],
                    let cls = NSClassFromString(Bundle.main.namespace + "." + clsName) as? UIViewController.Type
            else
        {
            return UIViewController()
        }
        
        //视图控制器
        let vc = cls.init()
        vc.title = title
        
        let nav = MMNavigationController(rootViewController:vc)
        
        return nav;
    }
}
